﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using umbraco.cms.businesslogic.member;
namespace Ulriksen.Umbraco.OpenId.Web
{
    public partial class MemberOpenIds : System.Web.UI.UserControl
    {
        protected void Page_Load(object sender, EventArgs e)
        {
            int currentMember = umbraco.cms.businesslogic.member.Member.CurrentMemberId();
            if (currentMember == 0)
                return;

            umbraco.cms.businesslogic.member.Member member = new umbraco.cms.businesslogic.member.Member(currentMember);

            List<string> openIds = member.GetOpenIds();

            foreach (string openId in openIds)
            {
                
                AttachedOpenId uc = (AttachedOpenId)Page.LoadControl("~/usercontrols/AttachedOpenId.ascx");
                
                uc.OpenId = openId;
                  if (OpenIdMember.OpenIdToUserName(openId) == member.LoginName)
                      uc.ReadOnly = true;

                 openIdsPlaceholder.Controls.Add(uc);
                 
            }
            openIdsPlaceholder.Visible = true;

                
        }
    }
}